package io.renren.modules.oatools.controller;

import io.renren.common.annotation.LogOperation;
import io.renren.common.utils.Result;
import io.renren.modules.oatools.dto.FieldsDTO;
import io.renren.modules.oatools.entity.InvokeEntity;
import io.renren.modules.oatools.service.FieldsService;
import io.renren.modules.oatools.service.InvokeService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 提供给OA调用
 *
 * @author xhtang 173101649@qq.com
 * @since 1.0.0 2024-06-15
 */
@RestController
@RequestMapping("analysisTools")
@Tag(name = "解析数据")
public class AnalysisToolsController {
    private static final Logger logger = LoggerFactory.getLogger(AnalysisToolsController.class);
    @Autowired
    private InvokeService invokeService;

    @Autowired
    private FieldsService fieldsService;

    @PostMapping("fromData")
    @LogOperation("接收表单数据")
    public Result fromData(@RequestBody Map<String, Object> formData, String formNum) {
        String sendData = null;

        InvokeEntity invoke = invokeService.getInvokeByNumber(formNum);
        if (invoke == null) {
            return new Result().error("未找到对应的接口数据");
        }
        Map<String, Object> fields = new HashMap<>();
        fields.put("invokeId", invoke.getId());
        List<FieldsDTO> listFields = fieldsService.list(fields);

        /**
         * 传递数据集合
         * 1. 排序
         * 2. 考虑是否是集合
         */
        Map<String, Object> sendMap = new HashMap<>();
        for (FieldsDTO field : listFields){
            //TODO 待完善 需要写一个工具类用于转换数据，把OA数据转换成接口数据
            sendMap.put(field.getTargetFields(),"");
        }

        //TODO 待完善 调用接口发起请求
        return new Result().ok(formData);
    }
}